﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CoordinateSystem.drawutils;

namespace CoordinateSystem.Controls
{
    public partial class DrawLayer : UserControl
    {
        private Font _tagFont;
        private Color _tagColor=Color.Red;
        private Color _backColor=Color.Black;
        private Color _lineColor=Color.White;
        private int _lineWidth=2;
        private int _Bound=20;
        private int _Scales=10;
        private Axis _AxisX = new Axis();
        private Axis _AxisY = new Axis(AxisType.Y);

        public int Scales
        {
            get
            {
                return _Scales;
            }
            set
            {
                _Scales = value;
                _AxisX.Scale = value;
                _AxisY.Scale = value;
            }
        }

        public int Bound
        {
            get
            {
                return _Bound;
            }
            set
            {
                _Bound = value;
                _AxisX.Margin = Bound;
                _AxisY.Margin = Bound;
                Invalidate();
            }
        }
        public Font TagFont
        {
            get
            {
                return _tagFont;
            }
            set
            {
                _tagFont = value;
                Invalidate();
            }
        }

        public Color TagColor
        {
            get
            {
                return _tagColor;
            }
            set
            {
                _tagColor = value;
                Invalidate();
            }
        }

        public Color BColor
        {
            get
            {
                return _backColor;
            }
            set
            {
                _backColor = value;
                BackColor = value;
                _AxisX.EraserColor = value;
                _AxisY.EraserColor = value;
                Invalidate();
            }
        }

        public Color LineColor
        {
            get
            {
                return _lineColor;
            }
            set
            {
                _AxisX.LineColor = value;
                _AxisY.LineColor = value;
                _lineColor = value;
                Invalidate();
            }
        }

        public int LineWidth
        {
            get
            {
                return _lineWidth;
            }
            set
            {
                _AxisX.LineWidth = value;
                _AxisY.LineWidth = value;
                _lineWidth = value;
                Invalidate();
            }
        }

        public Axis AxisX
        {
            get
            {
                return _AxisX;
            }
        }

        public Axis AxisY
        {
            get
            {
                return _AxisY;
            }
        }

        public DrawLayer()
        {
            InitializeComponent();
            
            Graphics g = this.CreateGraphics();
            _AxisY.Cavas = g;
            _AxisX.Cavas = g;
            Bound = 20;
            Scales = 10;
        }

        /// <summary>
        /// 绘制控件
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPaint(PaintEventArgs e)
        {
            _AxisX.Height = this.Height;
            _AxisX.Width = this.Width;
            _AxisY.Height = this.Height;
            _AxisY.Width = this.Width;
            _AxisX.DrawObject();
            _AxisY.DrawObject();
            base.OnPaint(e);
        }

        private void DrawLayer_SizeChanged(object sender, EventArgs e)
        {
            Invalidate();
        }
    }
}
